﻿using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Aliphant.UI;
using Aliphant.UI.Forms.Notify;
using Aliphant.UI.Widgets;
using Aliphant.UI.Windows;

using static System.Net.Mime.MediaTypeNames;

using Timer = System.Timers.Timer;

namespace TestModule.Widgets
{
    /// <summary>
    /// WidgetsClock.xaml 的交互逻辑
    /// </summary>
    public partial class WidgetClock : BaseWidget, IWidget
    {
        private bool _settingStatus;
        private Timer _timer;


        public WidgetClock()
        {
            InitializeComponent();

            _timer = new Timer();
            _timer.Interval = 500;
            _timer.AutoReset = true;
            _timer.Elapsed += TimeTick;
            _timer.Start();
            _timer.Enabled = true;
        }

        public void Init(Widget widget)
        {

        }

        public string? QuickButton1Tip => "菜单";

        public string? QuickButton2Tip => string.Empty;

        public string? QucikButton1Icon => "Icon.TriangleDown";

        public string? QucikButton2Icon => null;

        public void SetScriptPath(string scriptPath)
        {

        }

        public void QuickAction1()
        {
            if (_settingStatus)
            {
                _settingStatus = false;
                settings.Visibility = Visibility.Collapsed;
            }
            else
            {
                _settingStatus = true;
                settings.Visibility = Visibility.Visible;
            }
        }

        public void QuickAction2()
        {

        }

        public void Close()
        {
            _timer.Stop();
        }

        private void TimeTick(object? sender, ElapsedEventArgs e)
        {
            DateTime now = DateTime.Now;
            System.Windows.Application.Current.Dispatcher.BeginInvoke(() =>
            {
                this.Hour.Text = now.ToString("HH");
                this.Minute.Text = now.ToString("mm");
                this.Second.Text = now.ToString("ss");
            });
        }
    }
}
